<template>
  <page-header-wrapper>
    <a-card :bordered="false">

      <s-table
        ref="table"
        size="default"
        rowKey="id"
        :showPagination="false"
        :columns="columns"
        :data="loadData"
      >
         <span slot="is_reward" slot-scope="text, record">
          <a-badge :status="record.is_reward === '1' ? 'success' : 'default'" :text="record.is_reward === '1' ? '已入职' : '未入职'" />
        </span>
        <span slot="user_avatar" slot-scope="text, record">
          <a-avatar shape="square" :src="$staticPrefix(record.user.avatar)"/>
        </span>
        <span slot="recommend_avatar" slot-scope="text, record">
          <a-avatar shape="square" :src="$staticPrefix(record.recommend.avatar)"/>
        </span>
        <span slot="created_at" slot-scope="text">
          <span>{{ text | dayjs }}</span>
        </span>
        <span slot="updated_at" slot-scope="text">
          <span>{{ text | dayjs }}</span>
        </span>
      </s-table>
    </a-card>
  </page-header-wrapper>
</template>

<script>
import moment from 'moment'
import {STable, Ellipsis} from '@/components'
import {getList} from '@/api/invite'

const columns = [
  {
    title: '推荐人头像',
    align: 'center',
    dataIndex: 'user_avatar',
    scopedSlots: {customRender: 'user_avatar'}
  },
  {
    title: '推荐人',
    align: 'center',
    dataIndex: 'user',
    customRender: (e, record) => {
      return record.user.nickName;
    }
  },
  {
    title: '被推荐人头像',
    align: 'center',
    dataIndex: 'recommend_avatar',
    scopedSlots: {customRender: 'recommend_avatar'}
  },
  {
    title: '被推荐人',
    align: 'center',
    dataIndex: 'recommend',
    customRender: (e, record) => {
      return record.recommend.nickName;
    }
  },
  {
    title: '是否入职',
    align: 'center',
    dataIndex: 'is_reward',
    scopedSlots: {customRender: 'is_reward'}
  },
  {
    title: '创建时间',
    align: 'center',
    dataIndex: 'created_at',
    scopedSlots: {customRender: 'created_at'}
  },
  {
    title: '更新时间',
    align: 'center',
    dataIndex: 'updated_at',
    scopedSlots: {customRender: 'updated_at'}
  },
]

export default {
  name: 'AD',
  components: {
    STable,
    Ellipsis,
  },
  data() {
    this.columns = columns
    return {
      // create model
      visible: false,
      confirmLoading: false,
      mdl: null,
      // 查询参数
      queryParam: {},
      // 加载数据方法 必须为 Promise 对象
      loadData: parameter => {
        const requestParameters = Object.assign({}, parameter, this.queryParam)
        return getList(requestParameters)
          .then(res => {
            return res.data
          })
      },
      selectedRowKeys: [],
      selectedRows: []
    }
  },
  methods: {
    resetSearchForm() {
      this.queryParam = {
        date: moment(new Date())
      }
    },
  }
}
</script>
